<script setup>
    import { ref, watch,  defineProps, defineEmits} from 'vue'
    import { useVModel } from '@vueuse/core'
    import request from "../../common/utils/request"

    const props = defineProps({
        visible: {
            type: Boolean,
            default: false
        },
        app_id: {
            type: Number,
            required: true
        },
        question: {
            type: String,
            default: ''
        }
    })
    const emit = defineEmits(['update:visible'])
    const modalVisible = useVModel(props, 'visible', emit)
    const list = ref([])
    const spinning = ref(false)

    const getQuestionSimilarity = async () => {
        spinning.value = true
        const { data } = await request.get('work_ai', '/api/app/chat/search_test', { app_id: props.app_id, question: props.question })
        list.value = data
        spinning.value = false
    }

    watch(modalVisible, () => {
        if (modalVisible.value) {
            getQuestionSimilarity()
        } else {
            list.value = []
        }
    })
</script>

<template>
    <a-drawer v-model:visible="modalVisible" title="相似度查询" width="600px">
        <a-spin :spinning="spinning">
            <a-collapse>
                <a-collapse-panel :key="index" :header="`文档${index + 1}: 相似度 ${item.score}`" :show-arrow="false" v-for="(item, index) in list">
                    <p>{{ item.question }}</p>
                </a-collapse-panel>
            </a-collapse>
        </a-spin>
    </a-drawer>
</template>

<style lang="less" scoped>

</style>